

// 240.搜索二维矩阵II
class Solution {
public:
    bool searchMatrix(vector<vector<int>>& matrix, int target) {
        int n = matrix.size() , m = matrix[0].size();
        // 从(0  , m) 位置开始找 , target大就向下,否则向上
        int i = 0 , j = m - 1;
        while(i >= 0 && i < n && j >= 0 && j < m)
        {
            if(matrix[i][j] > target) j--;
            else if(matrix[i][j] < target) i++;
            else return true;
        }            
        return false;
    }
};